home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / v cisle / htttrack / httrack-3.41-3.exe / {app} / src / htsinthash.h < prev    next >
C/C++ Source or Header  |  2006-08-19  |  6KB  |  136 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: httrack.c subroutines:                                 */
  34. /*       hash table system (fast index)                         */
  35. /* Author: Xavier Roche                                         */
  36. /* ------------------------------------------------------------ */
  37.  
  38. // inthash -- simple hash table, using a key (char[]) and a value (uintptr_t)
  39.  
  40. #ifndef HTSINTHASH_DEFH
  41. #define HTSINTHASH_DEFH 
  42.  
  43. /* Includes */
  44. #ifdef _WIN32
  45. #include <stddef.h>
  46. #elif (defined(SOLARIS) || defined(sun) || defined(HAVE_INTTYPES_H) \
  47.   || defined(BSD) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD_kernel__))
  48. #include <inttypes.h>
  49. #else
  50. #include <stdint.h>
  51. #endif
  52.  
  53. // value
  54. typedef union inthash_value {
  55.   uintptr_t intg;                /* integer value */
  56.   void* ptr;                     /* ptr value */
  57. } inthash_value;
  58.  
  59. #define INTHASH_VALUE_NULL { 0 }
  60.  
  61. // simple hash table for other routines
  62. #ifndef HTS_DEF_FWSTRUCT_inthash_chain
  63. #define HTS_DEF_FWSTRUCT_inthash_chain
  64. typedef struct inthash_chain inthash_chain;
  65. #endif
  66. struct inthash_chain {
  67.   char* name;                    /* key (name) */
  68.   inthash_value value;           /* value */
  69.   struct inthash_chain* next;    /* next element */
  70. };
  71.  
  72. typedef void (* t_inthash_freehandler)(void* value);
  73.  
  74. /* inthash structure */
  75. #ifndef HTS_DEF_FWSTRUCT_struct_inthash
  76. #define HTS_DEF_FWSTRUCT_struct_inthash
  77. typedef struct struct_inthash struct_inthash, *inthash;
  78. #endif
  79. struct struct_inthash {
  80.   inthash_chain** hash;
  81.   unsigned int nitems;
  82.   t_inthash_freehandler free_handler;
  83.   unsigned int hash_size;
  84.   unsigned short flag_valueismalloc;
  85. };
  86.  
  87. // enumeration
  88. #ifndef HTS_DEF_FWSTRUCT_struct_inthash_enum
  89. #define HTS_DEF_FWSTRUCT_struct_inthash_enum
  90. typedef struct struct_inthash_enum struct_inthash_enum;
  91. #endif
  92. struct struct_inthash_enum {
  93.   inthash table;
  94.   int index;
  95.   inthash_chain* item;
  96. };
  97.  
  98. /* Library internal definictions */
  99. #ifdef HTS_INTERNAL_BYTECODE
  100.  
  101. // main functions:
  102.  
  103. /* Hash functions: */
  104. inthash inthash_new(int size);                                            /* Create a new hash table */
  105. int     inthash_created(inthash hashtable);                               /* Test if the hash table was successfully created */
  106. unsigned int inthash_nitems(inthash hashtable);                           /* Number of items */
  107. void    inthash_delete(inthash* hashtable);                               /* Delete an hash table */
  108. void    inthash_value_is_malloc(inthash hashtable,int flag);              /* Is the 'value' member a value that needs to be free()'ed ? */
  109. void    inthash_value_set_free_handler(inthash hashtable,                 /* value free() handler (default one is 'free') */
  110.                                        t_inthash_freehandler free_handler);
  111. /* */
  112. int     inthash_read(inthash hashtable,const char* name,intptr_t* intvalue);    /* Read entry from the hash table */
  113. int     inthash_readptr(inthash hashtable,const char* name,intptr_t* intvalue); /* Same function, but returns 0 upon null ptr */
  114. int     inthash_exists(inthash hashtable, const char* name);                    /* Is the key existing ? */
  115. /* */
  116. int     inthash_read_value(inthash hashtable,const char* name,inthash_value* value);
  117. int     inthash_write_value(inthash hashtable,const char* name,inthash_value value);
  118. void    inthash_add_value(inthash hashtable, const char* name, inthash_value value);
  119. /* */
  120. int     inthash_read_pvoid(inthash hashtable,const char* name, void** value);
  121. int     inthash_write_pvoid(inthash hashtable,const char* name, void* value);
  122. void    inthash_add_pvoid(inthash hashtable, const char* name, void* value);
  123. /* */
  124. void    inthash_add(inthash hashtable,const char* name,intptr_t value);    /* Add entry in the hash table */
  125. void*   inthash_addblk(inthash hashtable,const char* name,int blksize);    /* Add entry in the hash table and set value to a new memory block */
  126. int     inthash_write(inthash hashtable,const char* name,intptr_t value);  /* Overwrite/add entry in the hash table */
  127. int     inthash_inc(inthash hashtable,const char* name);                   /* Increment entry in the hash table */
  128. int     inthash_remove(inthash hashtable,const char* name);                /* Remove an entry from the hashtable */
  129. /* */
  130. struct_inthash_enum inthash_enum_new(inthash hashtable);             /* Start a new enumerator */
  131. inthash_chain* inthash_enum_next(struct_inthash_enum* e);           /* Fetch an item in the enumerator */
  132. /* End of hash functions: */
  133. #endif
  134.  
  135. #endif
  136.